﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoDataUpdateTool
{
    public struct BusRouteInfo
    {

        public string direction;
        public int stationSequence;
        public string stationName;
        public string stationType;
        public string longitude;
        public string latitude;
        public string angle;
        public BusRouteInfo(string di, int stq, string stn ,string stt, string lon, string lat, string ang)
        {
            direction = di;
            stationSequence = stq;
            stationName = stn;
            stationType = stt;
            longitude = lon;
            latitude = lat;
            angle = ang;

        }
    }

    public class DataParse
    {
        public static List<BusRouteInfo> BusRouteInfoList;

        private BusRouteInfo BusRutInfo;

        public List<BusRouteInfo> GetList{
            get { return BusRouteInfoList; }
        }
        public void Initializer() {
            BusRouteInfoList = new List<BusRouteInfo>();
            BusRutInfo = new BusRouteInfo("0",0,"0","0","0","0","0");
        }

        public DataParse() { Initializer(); }
        public DataParse(string fileName)
        {
            Initializer();
            string[] lines = File.ReadAllLines(fileName,Encoding.GetEncoding("gb2312"));
            int count = 0;
            foreach (var line in lines)
            {
                // Process line
               
                if (line.Any(Char.IsDigit) == true) { ProcessLine(line, ++count); }

            }
            //using (var streamReader = File.OpenText(fileName))
            //{
            //    var lines = streamReader.ReadToEnd().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            //    foreach (var line in lines)
            //    { 
            //        // Process line
            //        int count = 0;
            //        if (line.Any(Char.IsDigit) == true) { count++; ProcessLine(line,++count); }
                        
            //    }
            //}
        }

        public void ProcessLine(string line,int count){
            string[] strArray = line.Split(',');
            if (strArray.Length <= 12) return;
            BusRutInfo.direction = strArray[0];
            BusRutInfo.stationSequence = count;
            BusRutInfo.stationName = strArray[2];
            BusRutInfo.stationType = strArray[3];
            //BusRutInfo.latitude = strArray[12];
            //BusRutInfo.longitude = strArray[13];
            string[] strInArray = strArray[12].Split(' ');
            BusRutInfo.latitude = strInArray[0];
            BusRutInfo.longitude = strInArray[1];
            BusRouteInfoList.Add(BusRutInfo);
        }

    }
}
